import 'package:flutter/foundation.dart';
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:get/get.dart';
import 'package:leader_help/utils/component/component.dart';
import 'package:leader_help/utils/util.dart';

import 'controller.dart';

class RegisterPage extends GetView<RegisterController> {
  const RegisterPage({Key? key}) : super(key: key);

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: presentAppBar(context),
      backgroundColor: ColorsUtil.white,
      body: WillPopScope(
          child: Padding(
            padding: EdgeInsets.symmetric(horizontal: 31.w),
            child: Column(
              children: [
                SizedBox(
                  height: 46.w,
                ),
                Text(
                  '注册',
                  style: pfSCStyle(color: ColorsUtil.title, fontSize: 24.sp),
                ),
                SizedBox(
                  height: 40.w,
                ),
                UITextField(
                  prefixIcon: Text(
                    '账号',
                    style: pfMediumStyle(
                        color: ColorsUtil.title, fontSize: font14),
                  ),
                  hintText: '请输入账号',
                  prefixWidth: 70.w,
                  controller: controller.state.accountCtrl,
                ),
                CodeField(controller: controller.state.codeCtrl),
                Obx(
                  () => UITextField(
                      controller: controller.state.pwdCtrl,
                      prefixIcon: Text(
                        '密码',
                        style: pfMediumStyle(
                            color: ColorsUtil.title, fontSize: font14),
                      ),
                      hintText: '请输入密码',
                      prefixWidth: 70.w,
                      obscureText: controller.state.obscureText.value,
                      // inputFormatters: [
                      //   FilteringTextInputFormatter.allow(
                      //       RegExp(r'^([0-9]+$)([a-zA-Z]+$)[0-9A-Za-z]{6,16}$'))
                      // ],
                      suffixIcon: InkWell(
                        onTap: () {
                          controller.state.obscureText.value =
                              !controller.state.obscureText.value;
                        },
                        child: Icon(
                          controller.state.obscureText.value == true
                              ? IconUtil.eye_close
                              : IconUtil.eye_open,
                          color: ColorsUtil.content,
                          size: 15.w,
                        ),
                      )),
                ),
                Obx(
                  () => UITextField(
                      controller: controller.state.pwd1Ctrl,
                      prefixIcon: Text(
                        '确认密码',
                        style: pfMediumStyle(
                            color: ColorsUtil.title, fontSize: font14),
                      ),
                      hintText: '请输入确认密码',
                      prefixWidth: 70.w,
                      obscureText: controller.state.obscureText.value,
                      suffixIcon: InkWell(
                        onTap: () {
                          controller.state.obscureText.value =
                              !controller.state.obscureText.value;
                        },
                        child: Icon(
                          controller.state.obscureText.value == true
                              ? IconUtil.eye_close
                              : IconUtil.eye_open,
                          color: ColorsUtil.content,
                          size: 15.w,
                        ),
                      )),
                ),
                SizedBox(
                  height: 51.w,
                ),
                ExpandedButton(
                  text: '注册',
                  onPressed: controller.register,
                ),
                SizedBox(
                  height: 24.w,
                ),
                Row(
                  mainAxisAlignment: MainAxisAlignment.spaceBetween,
                  children: [
                    RichText(
                      text: TextSpan(
                          text: '已有账号，',
                          style: pfMediumStyle(
                            color: ColorsUtil.content,
                            fontSize: font14,
                          ),
                          children: [
                            TextSpan(
                              text: '立即登录',
                              recognizer: controller.state.loginGesture,
                              style: pfMediumStyle(
                                  color: ColorsUtil.blue, fontSize: font14),
                            ),
                          ]),
                    ),
                    RichText(
                      text: TextSpan(
                        text: '忘记密码',
                        recognizer: controller.state.forgotGesture,
                        style: pfMediumStyle(
                          color: ColorsUtil.content,
                          fontSize: font14,
                        ),
                      ),
                    ),
                  ],
                ),
              ],
            ),
          ),
          onWillPop: () async {
            return false;
          }),
    );
  }
}
